package com.jiyun.service.impl;

import cn.hutool.json.JSONUtil;
import cn.hutool.jwt.JWTUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiyun.feign.Feign;
import com.jiyun.mapper.MemberMapper;
import com.jiyun.model.day14.Member;
import com.jiyun.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ${王坤}
 * @Author itmei
 * @Date 2023/8/22 18:39
 */
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private Feign feign;

    @Override
    public String login(Member member) {
        Member login = feign.login(member);
        if (login!=null){
            Map map=new HashMap();
            map.put("token",login.getId());
            String token= JWTUtil.createToken(map,"1".getBytes());
            redisTemplate.opsForValue().set(token, JSONUtil.toJsonStr(login));
            return token;
        }else {
            return null;
        }
    }
}
